﻿@model PagingDataSet<User>
@{
    Layout = "_Follow";
    List<Category> categoriesShow = ViewData.Get<List<Category>>("categoriesShow", null);
    long? groupId = ViewData.Get<long?>("groupId", null);
    Follow_SortBy sortBy = ViewData.Get<Follow_SortBy>("sortBy", Follow_SortBy.DateCreated_Desc);
    long userId = ViewData.Get<long>("userId", 0);
    int followedCount = ViewData.Get<int>("followedCount", 0);
    Dictionary<long, string> noteNameDic = ViewData.Get<Dictionary<long, string>>("noteNameDic", null);
    Dictionary<long, bool> isMutualDic = ViewData.Get<Dictionary<long, bool>>("isMutualDic", null);
    Dictionary<long, bool> isFollowedDic = ViewData.Get<Dictionary<long, bool>>("isFollowedDic", null);
    Dictionary<long, string> userCategoriesShowDic = ViewData.Get<Dictionary<long, string>>("userCategoriesShowDic", null);
    IEnumerable<MenuItem> menuItem = ViewData.Get<IEnumerable<MenuItem>>("categoriesLeft", null);

    long? applicationId = 1001;
}
@section Aside{
    @Html.Action("_FollowUser_Menu", "Follow", new { menu = FollowUserMenu.MyFolloweds })
}
<div class="tn-box tn-widget tn-widget-content tn-corner-all tnc-relation-follow">
    <div class="tn-box-content tn-widget-content tn-corner-all">
        <div class="tnc-relation-follow-wrap">
            <div class="tn-main-heading tn-border-gray tn-border-bottom">
                <h2>
                    收藏</h2>
                <span class="tn-count tn-text-note" id="allNum">（@followedCount）</span>
            </div>
            <div class="tn-tabs">
                <ul class="tn-tabs-nav tn-border-gray tn-border-bottom tn-helper-clearfix">
                    <li class="tn-widget-content tn-border-gray tn-border-trl" name="group-all">
                        @Html.Link("全部", SiteUrls.Instance().ManageFollowedUsers(Url.SpaceKey(), null), "全部", new { id = "group-all" })
                    </li>
                    <li class="tn-widget-content tn-border-gray tn-border-trl" name="group-@(FollowSpecifyGroupIds.Mutual)">
                        @Html.Link("相互收藏", SiteUrls.Instance().ManageFollowedUsers(Url.SpaceKey(), FollowSpecifyGroupIds.Mutual), "相互收藏")
                    </li>
                    <li class="tn-widget-content tn-border-gray tn-border-trl" name="group-@(FollowSpecifyGroupIds.Quietly)">
                        @Html.Link("悄悄收藏", SiteUrls.Instance().ManageFollowedUsers(Url.SpaceKey(), FollowSpecifyGroupIds.Quietly), "消消收藏")
                    </li>
                    <li class="tn-widget-content tn-border-gray tn-border-trl" name="group-@(FollowSpecifyGroupIds.UnGrouped)">
                        @Html.Link("未分组", SiteUrls.Instance().ManageFollowedUsers(Url.SpaceKey(), FollowSpecifyGroupIds.UnGrouped), "未分组")
                    </li>
                    @foreach (var item in categoriesShow)
                    {
                        <li class="tn-widget-content tn-border-gray tn-border-trl" name="group-@(item.CategoryId)" data-groupId="@item.CategoryId">
                            @Html.Link(StringUtility.Trim(item.CategoryName, 5), SiteUrls.Instance().ManageFollowedUsers(Url.SpaceKey(), item.CategoryId), item.CategoryName, new { id = "group-" + item.CategoryId })
                        </li>
                    }
                    <li class="tn-widget-content tn-border-gray tn-border-trl tn-state-more" 
                         @if (menuItem == null)
                         {
                              @Html.Raw("style=\"display:none;\"")                    
                         } id="moreLi"><a href="#" class="tn-action tn-action-text-icon-right" menu="#moreandmore">
                             <span class="tn-icon tn-smallicon-triangle-down"></span><span class="tn-action-text">
                                 更多</span></a>
                        <div class="tn-more-options tn-widget-content tn-border-gray" id="moreandmore" style="display: none;">
                            <ul class="tn-more-list" id="moreUl">
                                @if (menuItem != null)
                                {
                                    foreach (var item in menuItem)
                                    {
                                    <li><a href="@item.Url" class="tn-item-link">@item.Text</a></li>
                                    }
                                }
                            </ul>
                        </div>
                    </li>
                    <li class="tn-option"><a href="@SiteUrls.Instance()._EditFollowedUsersGroup(Url.SpaceKey(), -99)" plugin="dialog" class="tn-action tn-action-text-icon">
                        <span class="tn-icon tn-smallicon-add"></span><span class="tn-action-text">创建分组</span></a>
                    </li>
                </ul>
                <div class="tn-tabs-panel">
                    @if (groupId > 0)
                    {
                        <div class="tn-list-header tn-border-gray tn-border-bottom tnc-operating-wrap tn-bg-gray">
                            <div class="tn-toolbar-area tn-helper-clearfix">
                                <span class="tn-count tn-helper-right">该分组下有<strong id="groupFollowedUsersNum">@Model.TotalRecords</strong>人
                                </span><a class="tn-action tn-action-text-icon" href="@SiteUrls.Instance()._EditFollowedUsersGroup(Url.SpaceKey(), groupId)"  plugin="dialog">
                                    <span class="tn-icon tn-smallicon-write"></span><span class="tn-action-text">编辑分组</span></a>
                                <a class="tn-action tn-action-text-icon" href="@SiteUrls.Instance().DeleteFollowedUsersGroup(Url.SpaceKey(), groupId)" id="delete-group">
                                    <span class="tn-icon tn-smallicon-cross"></span><span class="tn-action-text">删除分组</span></a>
                                <a class="tn-action tn-action-text-icon" href="@SiteUrls.Instance()._BatchFollow(Url.SpaceKey(), groupId)", plugin="dialog">
                                    <span class="tn-icon tn-smallicon-add"></span><span class="tn-action-text">批量添加</span></a>
                                <a class="tn-action tn-action-text-icon" href="@SiteUrls.Instance().MyHome(Url.SpaceKey(),groupId,applicationId)"><span class="tn-icon tn-smallicon-microblog">
                                </span><span class="tn-action-text">浏览分组微博</span> </a>
                            </div>
                        </div>
                    }
                    else if (groupId == null)
                    {
                        <div class="tn-list-header tn-border-gray tn-border-bottom">
                            <div class="tn-list-header-row">
                                <div class="tn-filter">
                                    排序方式： <a href="@SiteUrls.Instance().ManageFollowedUsers(Url.SpaceKey(), groupId)" 
                             @if (sortBy == Follow_SortBy.DateCreated_Desc)
                             { @Html.Raw("class=\"tn-action tn-selected\"");
                             }
                             else
                             {@Html.Raw("class=\"tn-action\"");
                             }><span class="tn-action-text">收藏时间</span></a> <span class="tn-spacer tn-text-note">
                                 |</span> <a href="@SiteUrls.Instance().ManageFollowedUsers(Url.SpaceKey(), groupId, 2)"
                             @if (sortBy == Follow_SortBy.FollowerCount_Desc)
                             { @Html.Raw("class=\"tn-action tn-selected\"");
                             }
                             else
                             {@Html.Raw("class=\"tn-action\"");
                             }><span class="tn-action-text">粉丝数</span></a> <span class="tn-spacer tn-text-note">|</span>
                                    <a href="@SiteUrls.Instance().ManageFollowedUsers(Url.SpaceKey(), groupId, 1)"
                              @if (sortBy == Follow_SortBy.LastContent_Desc)
                              { @Html.Raw("class=\"tn-action tn-selected\"");
                              }
                              else
                              {@Html.Raw("class=\"tn-action\"");
                              }><span class="tn-action-text">最近更新的时间</span></a>
                                </div>
                            </div>
                        </div>
                    }
                    <div class="tnc-user-list">
                        @if (Model != null && Model.Count() > 0)
                        { 
                            <ul class="tn-list">
                                @foreach (var user in Model)
                                {
                                    <li class="tn-list-item tn-helper-clearfix tn-border-gray tn-border-bottom tn-hover" id="Follower_@(user.UserId)">
                                        <div class="tn-list-item-area-left">
                                            @Html.ShowUserAvatar(user.UserId, AvatarSizeType.Small, true, HyperLinkTarget._blank)
                                        </div>
                                        <div class="tn-list-item-area-main">
                                            <div class="tn-list-item-row">
                                                <a href="@SiteUrls.Instance().SpaceHome(user.UserName)"  class="tn-user-name" title="@user.DisplayName" target="_blank">
                                                    @StringUtility.Trim((user.DisplayName), 7)
                                                </a>
                                                @if (!isFollowedDic[user.UserId])
                                                {
                                                    <em>（
                                                        @if (!string.IsNullOrEmpty(noteNameDic[user.UserId].Trim()))
                                                        { 
                                                            <a href="@SiteUrls.Instance()._UpdateFollowedUserNoteName(Url.SpaceKey(), user.UserId)" class="tn-secondary-text" userId="@user.UserId" title="@noteNameDic[user.UserId]" plugin="dialog">
                                                                @StringUtility.Trim(noteNameDic[user.UserId], 7)
                                                            </a>
                                                        }
                                                        else
                                                        {
                                                            <a href="@SiteUrls.Instance()._UpdateFollowedUserNoteName(Url.SpaceKey(), user.UserId)" class="tn-secondary-text" userId="@user.UserId" title="设置备注" plugin="dialog">
                                                                @Html.Raw("设置备注")
                                                            </a>
                                                        }
                                                        ）</em> 
                                                }
                                                <div class="tnc-down-blkarrow tn-bg-deep tn-state-hidden" menu="#moreOptions@(user.UserId)">
                                                    <a href="#" class="tn-icon tn-smallicon-triangle-down"></a>
                                                    <div class="tn-more-options tn-widget-content tn-border-gray" id="moreOptions@(user.UserId)" style="display: none;">
                                                        <ul class="tn-more-list">
                                                            <li>@Html.Link("发私信", SiteUrls.Instance()._CreateMessage(Url.SpaceKey(), toUserId: user.UserId), "发私信", htmlAttributes: new { id = "messageUserIdLink", plugin = "dialog", @class = "tn-item-link" })</li>
                                                            <li>@Html.Link("取消收藏", SiteUrls.Instance().CancelFollow(Url.SpaceKey(), user.UserId), "取消收藏", new { name = "Follow", status = "1", followedUserId = user.UserId, @class = "tn-item-link" })
                                                            </li>
                                                            <li>@Html.Link("加入黑名单", SiteUrls.Instance().CreateStopedUser(Url.SpaceKey(), user.UserId), "加入黑名单", new { name = "StopUser", stopedUserId = user.UserId, @class = "tn-item-link" })
                                                            </li>
                                                            <li><a href="@Html.Raw(SiteUrls.Instance()._ImpeachReport(user.UserId, SiteUrls.Instance().SpaceHome(user.UserId), user.DisplayName))" rel="nofollow" plugin="dialog" class="tn-item-link">
                                                                举报</a></li>
                                                        </ul>
                                                    </div>
                                                </div>
                                                <div class="tnc-relationship">
                                                    <span class="tn-explain-icon">
                                                        @if (isMutualDic[user.UserId])
                                                        {
                                                            <span class="tn-icon tn-smallicon-friendly"></span><span class="tn-icon-text">相互收藏</span>
                                                        }</span> <span class="tn-explain-icon">
                                                            @if (isFollowedDic[user.UserId])
                                                            {
                                                                <span class="tn-icon tn-smallicon-sneak"></span><span class="tn-icon-text">悄悄收藏</span> 
                                                            }</span>
                                                </div>
                                                @if (!isFollowedDic[user.UserId])
                                                {
                                                    <div class="tnc-crew-ungroup">
                                                        <a class="tn-action tn-action-text-icon-right" menu="#group_list_@(user.UserId)" url="@SiteUrls.Instance()._SetGroupForUser(Url.SpaceKey(), user.UserId, groupId)">
                                                            <span class="tn-icon tn-smallicon-triangle-down"></span>
                                                            @{
                                                    string url = SiteUrls.Instance()._SetGroupForUser(Url.SpaceKey(), user.UserId, groupId);
                                                            }
                                                            @if (!string.IsNullOrEmpty(userCategoriesShowDic[user.UserId]))
                                                            {
                                                                <span class="tn-action-text" name="group_list_@(user.UserId)"  >
                                                                    @StringUtility.Trim(userCategoriesShowDic[user.UserId], 6)</span>
                                                            }
                                                            else
                                                            {
                                                                <span class="tn-action-text" name="group_list_@(user.UserId)" >未分组</span>
                                                            }</a>
                                                        <div id="group_list_@(user.UserId)" class="tn-menu tn-widget tn-widget-content tn-corner-all" style="z-index:999999; display:none" >
                                                        </div>
                                                    </div>
                                                }
                                            </div>
                                            @if (user.Profile != null)
                                            { 
                                                <div class="tn-list-item-row">
                                                    <div class="tn-location">
                                                        @if (user.Profile.Gender == GenderType.FeMale)
                                                        {@Html.Icon(IconTypes.SmallFemale, "女")}
                                                        @if (user.Profile.Gender == GenderType.Male)
                                                        {@Html.Icon(IconTypes.SmallMale, "男")}
                                                        @Formatter.FormatArea(user.Profile.NowAreaCode, true)
                                                    </div>
                                                </div>
                                            }
                                            <div class="tn-list-item-row tnc-usernums">
                                                <span>收藏 <a href="@SiteUrls.Instance().ListFollowedUsers(user.UserName)"><strong>@user.FollowedCount</strong></a></span>
                                                <span class="tn-spacer tn-text-note">|</span> <span>粉丝 <a href="@SiteUrls.Instance().ListFollowers(user.UserName)">
                                                    <strong>@user.FollowerCount
                                                    </strong></a></span><span class="tn-spacer tn-text-note">|</span> <span>内容 <strong>@user.ContentCount</strong></span>
                                            </div>
                                            @if (user.Profile != null && !string.IsNullOrEmpty(user.Profile.Introduction.Trim()))
                                            {
                                                <div class="tn-list-item-row">
                                                    简介：
                                                    @HtmlUtility.TrimHtml(user.Profile.Introduction,100)
                                                </div>
                                            }
                                        </div>
                                    </li>
                                }
                            </ul>
                        }
                        else
                        { 
                            <div class="tn-no-data">
                                分组内暂无用户！</div>
                        }
                        <div class="tn-pagination">
                            @Html.PagingButton(Model, PaginationMode.NumericNextPrevious, 5)
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">

    $(document).ready(function () {

        if ('@groupId' == '') {
            $("li[name='group-all']").addClass("tn-tabs-selected");
        }
        else {
            $("li[name='group-@groupId']").addClass("tn-tabs-selected");
        }
        var totalNum = parseInt("@followedCount");

        $("#delete-group").click(function (e) {
            e.preventDefault();
            $this = $(this);
            art.dialog.confirm('确定删除该分组吗？&nbsp;&nbsp;', function () {
                $.ajax({
                    type: "Post",
                    url: $this.attr("href"),
                    success: function () {
                        window.location.href = $("#group-all").attr("href");
                    },
                    error: function () {
                        art.dialog.tips("删除失败", 1.5, -1);
                    }
                });
            });
        });

        $("a[name='StopUser']").click(function (e) {
            e.preventDefault();
            $this = $(this);
            var stopedUserId = $this.attr("stopedUserId");

            art.dialog.confirm('加入黑名单会解除关系，确定要加入黑名单吗？&nbsp;&nbsp;', function () {
                $.ajax({
                    type: "Get",
                    url: $this.attr("href"),
                    success: function (msg) {
                        totalNum = totalNum - 1;
                        $("#allNum").text("（" + totalNum + "）");
                        $("#Follower_" + stopedUserId).fadeOut();
                        var num = parseInt($("#groupFollowedUsersNum").text()) - 1;
                        $("#groupFollowedUsersNum").text(num);
                    },
                    error: function () {
                        art.dialog.tips("删除失败", 1.5, -1);
                    }
                });
            });
        });



        $("a[name='Follow']").click(function (e) {
            e.preventDefault();
            var $this = $(this);
            var followedUserId = $this.attr('followedUserId');

            art.dialog.confirm('确定要取消收藏用户吗？&nbsp;&nbsp;', function () {
                $.ajax({
                    type: "Post",
                    url: $this.attr("href"),
                    success: function (msg) {
                        totalNum = totalNum - 1;
                        $("#allNum").text("（" + totalNum + "）");
                        $("#Follower_" + followedUserId).fadeOut();
                        var num = parseInt($("#groupFollowedUsersNum").text()) - 1;
                        $("#groupFollowedUsersNum").text(num);
                    },
                    error: function () {
                        art.dialog.tips("删除失败", 1.5, -1);
                    }
                });
            });
        });

        $(".tn-more-options .tn-item-link").hover(
        function () {
            $(this).addClass("tn-bg-gray");
        },
        function () {
            $(this).removeClass("tn-bg-gray");
        });
    });
</script>
